﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;
using University.Workshop.Model;
using System.Resources;
using System.Reflection;
using System.Globalization;

[assembly: NeutralResourcesLanguageAttribute("en-US")]
namespace University.Workshop.Presenters.AppointmentFolder
{

    public class RegisterAppointmentPresenter
    {
        /// <summary>
        /// Declaring Variables
        /// </summary>
        private IRegisterAppointmentView view;
        private ResourceManager stringManager;

        //Methods

        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="view">The view that inteacts with the presenter</param>
        public RegisterAppointmentPresenter(IRegisterAppointmentView view)
        {
            this.view = view;
            stringManager = new ResourceManager("en-US", Assembly.GetExecutingAssembly());
        }

        /// <summary>
        /// Registers the new appointment
        /// </summary>
        public bool RegisterAppointment() 
        {
            bool verify = false;
            if (Business.PatientManager.PatientExists(view.NewAppointment.PatientId))
            {
                if (AppointmentManager.AreInputsCorrect(view.NewAppointment.PatientId, view.NewAppointment.DoctorId, view.NewAppointment.Date, view.NewAppointment.Time))
                {
                    if (AppointmentManager.RegisterAppointment(view.NewAppointment))
                    {
                        view.SetMessage(stringManager.GetString(SystemMessages.AppointmentCorrectRegister, System.Globalization.CultureInfo.CurrentCulture));
                        verify = true;
                    }
                    else
                        view.SetMessage(stringManager.GetString(SystemMessages.AppointmentUnknownError, CultureInfo.CurrentUICulture));
                }
                else
                    view.SetMessage(stringManager.GetString(SystemMessages.AppointmentInputsIncorrect, CultureInfo.CurrentUICulture));
            }
            else
                view.SetMessage(stringManager.GetString("The patient does not exist, register the patient first.", CultureInfo.CurrentUICulture));
            
            return verify;
        }

        public void CleanInputFields()
        {
            view.NewAppointment = new Appointment("","Escoja una Especialidad...","","","8:00","","");
        }
    }
} 